﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using LibrarySync2.Business.FileSystem;
using LibrarySync2.Business.FileSystem.Item;

namespace LibrarySync2.Business.Extensions
{
    public static class CollectionExtensionMethods
    {
        public static FileSystemItemBase FindMatchingItem(this List<FileSystemItemBase> list, FileSystemItemBase item)
        {
            if (list == null)
                throw new ArgumentNullException("list");
            if (item == null)
                throw new ArgumentNullException("item");

            return list.FirstOrDefault<FileSystemItemBase>(fsib => fsib.Equals(item));
        }

        public static bool ContainsItem(this List<FileSystemItemBase> list, FileSystemItemBase item)
        {
            if (list == null)
                throw new ArgumentNullException("list");
            if (item == null)
                throw new ArgumentNullException("item");

            return list.FindMatchingItem(item) != null;
        }

        public static MediaFile FindMatchingMediaFile(this List<MediaFile> list, string mediaFileId)
        {
            if (list == null)
                throw new ArgumentNullException("list");
            if (string.IsNullOrEmpty(mediaFileId))
                throw new ArgumentNullException("mediaFileId");

            return list.FirstOrDefault<MediaFile>(mf => mf.Id.Equals(mediaFileId, StringComparison.OrdinalIgnoreCase));
        }

        public static bool ContainsMediaFile(this List<MediaFile> list, string mediaFileId)
        {
            if (list == null)
                throw new ArgumentNullException("list");
            if (string.IsNullOrEmpty(mediaFileId))
                throw new ArgumentNullException("mediaFileId");

            return list.FindMatchingMediaFile(mediaFileId) != null;
        }
    }
}
